package com.sa07.config;

import java.util.Properties;

import com.sa07.bean.DbConstant;
import com.sa07.db.DbConfig;
import com.sa07.utils.StringUtils;

/**
 * 数据库配置初始化
 * 
 * @author Long.shangbo
 *
 * 2014-2-21 上午11:23:56
 */
public abstract class DataBaseConfigInit extends PropertiesConfigInit {

	@Override
	protected void analyzeProperties(Properties pro) {
		DbConfig dbConfig = new DbConfig();
		dbConfig.setDbIp(pro.getProperty(DbConstant.DB_IP));
		dbConfig.setDbPort(StringUtils.isNullOrEmpty(pro.getProperty(DbConstant.DB_PORT)) ? 0 : Integer.parseInt(pro.getProperty(DbConstant.DB_PORT)));
		dbConfig.setDbName(pro.getProperty(DbConstant.DB_NAME));
		dbConfig.setDbType(pro.getProperty(DbConstant.DB_TYPE));
		dbConfig.setDbUserName(pro.getProperty(DbConstant.DB_USERNAME));
		dbConfig.setDbUserPwd(pro.getProperty(DbConstant.DB_USERPWD));
		processConfig(dbConfig);
	}

	/**
	 * 处理数据库配置
	 * @param config
	 */
	protected abstract void processConfig(DbConfig config);
	
}
